package com.bing.services.impl;

import com.bing.Component.Context;
import com.bing.bean.weixin.ResponseMessage;
import com.bing.utils.Tuling;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by kaibb on 2014/12/6.
 */

public class TulingCommand extends AbstractCommandService {
    private final static Logger logger = LoggerFactory.getLogger(TulingCommand.class);

    private int order = 999;

    @Override
    public ResponseMessage handle(Context context) {
        logger.debug("图灵处理");

        ResponseMessage responseMessage = Tuling.talk(context.getRequestMessage());
        logger.info("返回数据:{}", responseMessage.toString());
        return responseMessage;
    }


    @Override
    protected Logger getLogger() {
        return logger;
    }

    @Override
    protected List<String> getContexts() {
        return new ArrayList<>();
    }

    @Override
    public boolean canHandle(Context context) {
        context.getUser().setCommand("");
        context.getUser().setLatestActive(new Date());
        if (StringUtils.hasText(context.getRequestMessage().getContent())) {
            context.getUser().setHistoryCommands(context.getRequestMessage().getContent());
        }
        userService.updateUser(context.getUser());
        return true;
    }

    @Override
    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }
}
